<include file="public@header"/>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Teacher/index')}">请假列表</a></li>
        <li class="active"><a href="{:url('Teacher/edit',array('id'=>$data->id,'is_teacher'=>$is_teacher))}">编辑请假</a></li>
    </ul>
    <div class="row margin-top-20">
        <div class="col-md-12 col-lg-10">
            <form action="{:url('Teacher/editPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
                <input type="hidden" name="id" value="{$data->id}">
                <input type="hidden" name="is_teacher" value="{$is_teacher}">
                <div class="row">
                    <div class="col-md-12">
                        <table class="table table-bordered chase_classroom_table">
                            <tr>
                                <th>班级<span class="form-required">*</span></th>
                                <td>
                                    <select class="form-control" name="class_id" id="input-class" style="width: 240px;">
                                        <option value='0'>全部</option>
                                        <notempty name="classes">
                                            <foreach name="classes" item="vo">
                                                <if condition="isset($data.class_id) && $data.class_id eq $vo.id">
                                                    <option value="{$vo.id}" selected>{$vo.name}</option>
                                                <else/>
                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                </if>
                                            </foreach>
                                        </notempty>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>课时<span class="form-required">*</span></th>
                                <td>
                                    <select class="form-control" name="leave_datetime" id="leave_datetime" style="width: 240px;">
                                        <option value="">全部</option>
                                        <notempty name="course_time">
                                            <foreach name="course_time" item="vo">
                                                <if condition="isset($data.leave_date) && $vo.date eq $data.leave_date && $vo.start_time eq $data.leave_start_time && $vo.end_time eq $data.leave_end_time">
                                                    <option value="{$vo.date},{$vo.start_time},{$vo.end_time}" selected>
                                                        {:date('Y-m-d',$vo.date)} {$vo.start_time}~{$vo.end_time} {$vo.week} {$vo.schedule}
                                                    </option>
                                                    <else/>
                                                    <option value="{$vo.date},{$vo.start_time},{$vo.end_time}">{:date('Y-m-d',$vo.date)} {$vo.start_time}~{$vo.end_time} {$vo.week} {$vo.schedule}</option>
                                                </if>
                                            </foreach>
                                        </notempty>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>事由<span class="form-required">*</span></th>
                                <td>
                                    <textarea class="form-control" id="input-content" name="reason" rows="8">{$data->reason}</textarea>
                                </td>
                            </tr>
                        </table>

                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                                <a class="btn btn-default" href="{:url('Teacher/index')}">{:lang('BACK')}</a>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<!--ajax layer 弹窗-->
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>

<script type="text/javascript">
    $(document).ready(function() {

        $('#input-class').on('change',function () {
            var sid = $(this).val();
            if(sid == 0){
                $('#leave_datetime').empty();
                var html = '<option value=\"0\">全部</option>';
                $('#leave_datetime').html(html);
                return false;
            }
            $.ajax({
                url:"{:url('Teacher/ajax_date')}",
                type:'post',
                dataType:'json',
                data:{"class_id":sid},
                success:function(jsonData){
                    console.log(jsonData);
                    $('#leave_datetime').empty();
                    var html = '<option value=\"\">全部</option>';

                    if(jsonData.code == 1){
                        $obj = jsonData.data;
                        for(var i in $obj){
                            html += '<option value=\"'+$obj[i].date+','+$obj[i].start_time+','+$obj[i].end_time+'\">'
                                +$obj[i].date+' '+$obj[i].start_time+'~'+$obj[i].end_time+' '+$obj[i].week+' '+$obj[i].schedule+'</option>';
                        }
                    }
                    $('#leave_datetime').html(html);
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        });
//        $('input[name="start"]').datepicker();
//        $('input[name="end"]').datepicker();
    });

</script>

</body>
